package com.enjoyor.soa.traffic.server.efoms.dubbo.invoke;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.ubms.dto.DeptInfoDto;
import com.enjoyor.soa.traffic.api.ubms.service.dubbo.DubboDeptInfoService;
import com.enjoyor.soa.traffic.api.ubms.service.dubbo.DubboDeviceInfoService;
import com.enjoyor.soa.traffic.api.ubms.service.dubbo.DubboPublicDicService;
import com.enjoyor.soa.traffic.frame.security.bean.dto.DataAccessRightDto;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Component
public class DubboUbmsServiceInvoke {

    @Reference(timeout = 3000)
    private DubboDeptInfoService deptService;

    @Reference(timeout = 3000)
    private DubboPublicDicService publicService;
    
	@Reference(timeout = 3000)
	private DubboDeviceInfoService deviceInfoService;
    
	public ResultPojo getSubDeptinfo(String parentId) {
		return deptService.getDeptInfoByParentId(parentId);
	}
	public ResultPojo getChildDeptInfoById(String parentId) {
		return deptService.getChildDeptInfoById(parentId);
	}
	public ResultPojo getDeptInfo(String deptId, String parentId, String deptName, String parentName, String orderSeq) {
		return deptService.getDeptInfo(deptId, parentId, deptName,parentName,orderSeq);
	}
	public ResultPojo getDeptInfoById(String deptId) {
		return deptService.getDeptInfoById(deptId);
	}
	public ResultPojo getDevInfoList(String devId,String devType,String devName,String deptId,String areaId,String orderSeq){
		return deviceInfoService.getDeviceInfo(devId, devType, devName, deptId, areaId, orderSeq);
	}
	public ResultPojo getDevInfoList(String devId,String devType){
		return deviceInfoService.getDeviceInfo(devId, devType, null, null, null, null);
	}
	/**
	 * 根据用户数据权限获取部门编号列表
	 * @param List<DataAccessRightDto> dataAccessRights
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<String> getSubDeptIds(List<DataAccessRightDto> dataAccessRights){
		List<String> listIds = new ArrayList<String>();
		for(DataAccessRightDto DataAccessRight:dataAccessRights)
		{
			ResultPojo resultPojo = this.getSubDeptinfo(DataAccessRight.getOrgId());
			if(resultPojo.getAppCode().equals("0"))
			{
				List<DeptInfoDto> listInfo = (List<DeptInfoDto>)resultPojo.getResultList();
				for(DeptInfoDto dto: listInfo)
				{
					listIds.add(dto.getDeptId());
				}	
			}
		}
		List<String> newList = new ArrayList<String>(new HashSet<String>(listIds)); //list去重
		return newList;
	}
	
	/**
	 * 根据参数ParentCode取字典信息
	 * @param parentCode
	 * @return
	 */
	public ResultPojo getPublicDicByParentCode(String parentCode)
	{
		ResultPojo resultPojo = publicService.getPublicDicByParentCode(parentCode);
		return resultPojo;
	}
}
